package com.ymatou.iapi.address.testcase;


import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.reflect.TypeToken;
import com.ymatou.iapi.address.service.AddressCall;
import com.ymt.base.YmatouEasyCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.utils.DiffUtil;

@TestSuite
public class Ts_Address {
	private static AddressCall fmc;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查看地址接口");
	}

	@Before
	public void caseUp() {
		fmc = new AddressCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(fmc.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_Address_001() {
		Logger.start(true,"查询消息成功");
		try {
			//http://base.iapi.xlobo.com/api/Area/GetAllAreaInfo
			//TODO 格式变更 需要手动查看
			//此接口透传 用来获取地址列表
			Logger.comment("sendMsg");
			fmc.callService();
			List<Map> m=(List<Map>) FormatUtil.GSONToObject(fmc.getReturnData(),new TypeToken<List<Map>>() {}.getType());
			
			Logger.verifyEquals(34, m.size(), "验证中国省份数据长度");
			List<Map> bjm=(List<Map>) m.stream().filter(info->{return info.get("name").equals("北京市");}).collect(Collectors.toList()).get(0).get("children");
			List<Map>  bjchhild=(List<Map>) bjm.get(0).get("children");
			Logger.debug(bjchhild);
//			bjchhild.forEach(ch->{
//				Logger.debug(ch);
//			});
			Logger.verifyEquals(17, bjchhild.size(), "验证北京市区数据长度");
			Logger.verifyEquals(1l,bjchhild.stream().filter(ch->{return ch.get("name").equals("朝阳区");}).count(), "验证北京市有朝阳区");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}